<?php
class Admin_Model_ContentModuleToPage extends Zend_Db_Table{
	protected $_name = 'content_module_to_page';
	protected $_primary = array('module_code','page_code');
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	
	////////////
	/* select*/
	//////////
	public function selectModuleBySortOrder($sort_order,$module_code,$page_code)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/contentmoduletopage/route/selectModuleBySortOrder/module_code/".$module_code."/page_code/".$page_code."/sort_order/".$sort_order);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];	
		return $data;
	}
	public function selectModuleByCode($page_code,$module_code)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/contentmoduletopage/route/selectModuleByCode/module_code/".$module_code."/page_code/".$page_code);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];	
		return $data;
	}
	
	////////////
	/* insert*/
	//////////
	public function insertModuleToPage($data)
	{// co dung
		
		$data['route'] = "insertModuleToPage";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/contentmoduletopage", $data);
		return $return->getBody();
	}
	
	////////////
	/* update*/
	//////////
	public function updatePageCodeByCode($page,$data)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$data['route'] = "updatePageCodeByCode";
		$data['page'] = $page;
		$return = $client->restPost("/contentmoduletopage", $data);
		
		return $return->getBody();
	}
	
	////////////
	/* delete*/
	//////////
	public function deleteModuleByCode($code,$page)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/contentmoduletopage/route/deleteModuleByCode/module_code/".$code."/page_code/".$page);
		return $return->getBody();
		
	}	
	public function deleteAllModuleByPageCode($page)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/contentmoduletopage/route/deleteAllModuleByPageCode/page_code/".$page);
		return $return->getBody();
	}
	public function updateContentModuleToPage($sort,$module,$page)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/contentmoduletopage/route/updateContentModuleToPage/sort/".$sort."/module_code/".$module."/page_code/".$page);
		return $return->getBody();
	}
}